package com.htgd.gardenexpo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConFood;
import com.htgd.gardenexpo.entity.GeConFoodShop;
import com.htgd.gardenexpo.entity.GeConFunSports;
import com.htgd.gardenexpo.dao.GeConFunSportsMapper;
import com.htgd.gardenexpo.page.FunSportsQuery;
import com.htgd.gardenexpo.service.IGeConFunSportsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.htgd.gardenexpo.vo.GeConFoodShopVO;
import com.htgd.gardenexpo.vo.GeConFunSportsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 趣运动表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-04-14
 */
@Service
public class GeConFunSportsServiceImpl extends ServiceImpl<GeConFunSportsMapper, GeConFunSports> implements IGeConFunSportsService {

    @Autowired
    private GeConFunSportsMapper geConFunSportsMapper;

    @Override
    public CommonResult add(GeConFunSports geConFunSports) {
        geConFunSports.setStatus("4");
        geConFunSportsMapper.insert(geConFunSports);
        return CommonResult.success("添加成功");
    }

    @Override
    public CommonResult edit(GeConFunSports geConFunSports) {
        geConFunSportsMapper.updateById(geConFunSports);
        return CommonResult.success("编辑成功");
    }

    @Override
    public CommonResult delete(String id) {
        geConFunSportsMapper.deleteById(id);
        return CommonResult.success("删除成功");
    }

    @Override
    public CommonResult pageList(String openId, FunSportsQuery funSportsQuery) {
        PageHelper.startPage(funSportsQuery.getPageNum(),funSportsQuery.getPageSize());
        List<GeConFunSportsVO> geConFunSportsVOS = geConFunSportsMapper.pageList(funSportsQuery);
        PageInfo<GeConFunSportsVO> list = new PageInfo<>(geConFunSportsVOS);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @Override
    public CommonResult details(String openId, String id) {
        GeConFunSportsVO geConFunSportsVO = new GeConFunSportsVO();

        //浏览加1
        lambdaUpdate().setSql("hit = hit +1")
                .eq(GeConFunSports::getId,id)
                .update();

        GeConFunSports geConFunSports = geConFunSportsMapper.selectById(id);
        BeanUtils.copyProperties(geConFunSports,geConFunSportsVO);


        return CommonResult.success("查询成功",geConFunSportsVO);
    }

    @Override
    public CommonResult review(GeConFunSports geConFunSports) {
        lambdaUpdate().eq(GeConFunSports::getId,geConFunSports.getId())
                .set(GeConFunSports::getStatus,geConFunSports.getStatus())
                .update();
        return CommonResult.success("审核成功");
    }
}
